package com.example.demo.service;

import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class OrderService {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void makeOrder(String userId,String productId,int num){
        String orderId = UUID.randomUUID().toString();
        System.out.println("订单生成成功"+orderId);
        String exchangeName = "fanout_order_exchange";
        String routingKey = "";
        rabbitTemplate.convertAndSend(exchangeName,routingKey,orderId);
    }

    public void makeOrderDirect(String userId,String productId,int num,String routingKey){
        String orderId = UUID.randomUUID().toString();
        System.out.println("订单生成成功"+orderId);
        String exchangeName = "direct_order_exchange";
//        String routingKey = "";
        rabbitTemplate.convertAndSend(exchangeName,routingKey,orderId);
    }

    public void makeOrderTopic(String userId,String productId,int num){
        String orderId = UUID.randomUUID().toString();
        System.out.println("订单生成成功"+orderId);
        String exchangeName = "topic_order_exchange";
//        String routingKey = "";
        String routingKey = "com.duanxin";
        /**
         * duanxin -> #.duanxin.#
         * sms -> com.#
         * email ->*.email.#
         */
        rabbitTemplate.convertAndSend(exchangeName,routingKey,orderId);
    }
}
